/*
 * Copyright 2007 www.luzand.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Depends on: ComponentsFactory.js

var yrprxKeyboardHelper = {
    VK_ESCAPE : Components.interfaces.nsIDOMKeyEvent.DOM_VK_ESCAPE,
    VK_SPACE  : Components.interfaces.nsIDOMKeyEvent.DOM_VK_SPACE,
    VK_LEFT   : Components.interfaces.nsIDOMKeyEvent.DOM_VK_LEFT,
    VK_RIGHT  : Components.interfaces.nsIDOMKeyEvent.DOM_VK_RIGHT,
    VK_UP     : Components.interfaces.nsIDOMKeyEvent.DOM_VK_UP,
    VK_DOWN   : Components.interfaces.nsIDOMKeyEvent.DOM_VK_DOWN,
    VK_PAGE_UP: Components.interfaces.nsIDOMKeyEvent.DOM_VK_PAGE_UP,
    VK_PAGE_DOWN : Components.interfaces.nsIDOMKeyEvent.DOM_VK_PAGE_DOWN,
    VK_HOME   : Components.interfaces.nsIDOMKeyEvent.DOM_VK_HOME,
    VK_END    : Components.interfaces.nsIDOMKeyEvent.DOM_VK_END,
    VK_INSERT : Components.interfaces.nsIDOMKeyEvent.DOM_VK_INSERT,
    VK_DELETE : Components.interfaces.nsIDOMKeyEvent.DOM_VK_DELETE,
    VK_F4     : Components.interfaces.nsIDOMKeyEvent.DOM_VK_F4,
    VK_F11    : Components.interfaces.nsIDOMKeyEvent.DOM_VK_F11,
    KEY_MASK_ATL : 2,
    KEY_MASK_CTRL : 4,
    KEY_MASK_META : 8,
    KEY_MASK_ACCEL : 4 /*KEY_MASK_CTRL*/
};

try
{
    var accelKey = yrprxComponentsFactory.getPreferencesServiceAsBranch().getIntPref("ui.key.accelKey");
    if (accelKey == Components.interfaces.nsIDOMKeyEvent.DOM_VK_META)
        yrprxKeyboardHelper.KEY_MASK_ACCEL = yrprxKeyboardHelper.KEY_MASK_META;
    else if (accelKey == Components.interfaces.nsIDOMKeyEvent.DOM_VK_ALT)
        yrprxKeyboardHelper.KEY_MASK_ACCEL = yrprxKeyboardHelper.KEY_MASK_ATL;
}
catch(ex)
{
    dump("Cannot get accel key! Exception : " + ex + "\n");
}

yrprxKeyboardHelper.getKeyboardModifiers = function (event)
{
    var modifiers = 0;

    if (event.altKey)  modifiers |= yrprxKeyboardHelper.KEY_MASK_ATL;
    if (event.ctrlKey) modifiers |= yrprxKeyboardHelper.KEY_MASK_CTRL;
    if (event.metaKey) modifiers |= yrprxKeyboardHelper.KEY_MASK_META;

    return modifiers;
}
